﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace 原型模式案例
{
    /// <summary>
    /// 原型接口
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public interface IPrototype<T>
    {
        T Clone(); // 通常是深拷贝
    }

    /// <summary>
    /// 具体原型类
    /// </summary>
    public class Resume : IPrototype<Resume>
    {
        public string Name { get; set; }        //名字
        public string Education { get; set; }   //教育经历
        public string Experience { get; set; }  //经验
        public string Age { get; set; }         //年龄
        public string Gender { get; set; }      //性别

        public Resume(string name)
        {
            Name = name;
        }

        /// <summary>
        /// 拷贝构造函数
        /// </summary>
        /// <param name="otherResume"></param>
        public Resume(Resume otherResume)
        {
            Name = otherResume.Name;
            Education = otherResume.Education;
            Experience = otherResume.Experience;
            Age = otherResume.Age;
            Gender = otherResume.Gender;
        }

        public Resume Clone()
        {
            return new Resume(this); // 深拷贝
        }

        public void Show()
        {
            Console.WriteLine($"姓名: {Name}, 教育经历: {Education}, 经验: {Experience}, 年龄: {Age}, 性别: {Gender}");
        }
    }


    /// <summary>
    /// 客户
    /// </summary>
    public class Client
    {
        /// <summary>
        /// 复制原型A
        /// </summary>
        /// <returns></returns>
        public Resume Clone(Resume original)
        {
            return original.Clone();
        }
    }



    class Program
    {
        static void Main(string[] args)
        {
            func1();
            Console.ReadKey();
        }


        static void func1()
        {
            Resume original = new Resume("张三");
            original.Education = "本科";
            original.Experience = "5年开发经验";
            original.Age = "25";
            original.Gender = "男";

            original.Show();

            Resume copy1 = original.Clone();
            copy1.Name = "李四";   //修改
            copy1.Age = "20";       //修改
            copy1.Experience = "6年开发经验";   //修改
            copy1.Show();

            Resume copy2 = original.Clone();
            copy2.Name = "王五";
            copy2.Education = "硕士";          //修改
            copy2.Show();
        }

    }
}
